local XMPQT = XLGetGlobal("XMPQT")

XMPQT.Helper = {}

function XMPQT.Helper.RunXmp(command)
	local path  = XMPQT.API:Call("GetXmpReg","Path")
	XMPQT.API:Call("SHExec",path,command)

end

XMPQT.TestCaseTable = nil

function XMPQT.Helper.GetTestCaseTable()
	local luapath = __document.."\\..\\..\\testcase\\TestCaseList.lua"
	--corrected By wubaolai
	--Bug desc:先卸载再读入list，能够保证内存中的TestCaseTable与TestCaseList文件保持一致
	if (XLModuleExists(luapath)) then
		XLUnloadModule(luapath)
	end
	--
	if not XLModuleExists(luapath) then
		local ft = XLLoadModule(luapath)
		if type(ft) == "table" and type(ft.GetSubTable) == "function" then 
			XMPQT.TestCaseTable = ft.GetSubTable()
		end
	end
	
	return XMPQT.TestCaseTable
end

function XMPQT.Helper.InsertTreeItem(parent,id,text,sstate)
	local treeMananger 	= XLGetObject("Xunlei.UIEngine.TreeManager")
	local rootObjTree 	= treeMananger:GetUIObjectTree("XMPQT.MainObjTree.Instance")
	local bkgObject 	= rootObjTree:GetUIObject("app.bkg")
	local treeCtrl 		= bkgObject:GetObject("mainwnd.body:mediaAdvanceInfo:layout:advanceMediaInfo.tree")
	local advanceInfoObj = bkgObject:GetObject("mainwnd.body:mediaAdvanceInfo")
	
	local attrTable = {_left = 0, _height = 23, _state = sstate,_text = text,_expandtype = "" and 2 or 0}
	treeCtrl:InsertChild(parent, id, attrTable, nil, true)	
	treeCtrl:AdjustItemPos()
end

function XMPQT.Helper.Split(szFullString, szSeparator)
	local nFindStartIndex = 1
	local nSplitIndex = 1
	local nSplitArray = {}
	while true do
	   local nFindLastIndex = string.find(szFullString, szSeparator, nFindStartIndex)
	   if not nFindLastIndex then
			nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, string.len(szFullString))
			break
	   end
	   nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, nFindLastIndex - 1)
	   nFindStartIndex = nFindLastIndex + string.len(szSeparator)
	   nSplitIndex = nSplitIndex + 1
	end
	return nSplitArray
end
